﻿@page "/sys/session"
@using System.Linq.Expressions;
@using Masa.Blazor.Presets;

@inject ISessionService SessionService
@namespace ThingsGateway.Web.Rcl
@attribute [Authorize]
@attribute [RolePermission]
@inject UserResoures UserResoures
@inherits CultureComponentBase
@layout MainLayout
<AppDataTable TItem="SessionOutput"
              SearchItem="SessionPageInput"
              AddItem="SessionOutput" EditItem="SessionOutput"
              SearchModel="@sessionSearch"
              QueryCall="sessionQueryCall"
              FilterHeaders="sessionFilterHeaders"
              IsMenuOperTemplate=false
              ShowQueryButton>

    <SearchTemplate>
        <MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 " @bind-Value="context.Account"
                    Outlined Label=@context.Description(x => x.Account) />
        <MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 " @bind-Value="context.Name"
                    Outlined Label=@context.Description(x => x.Name) />
        <MTextField Dense Style="max-width:200px;" HideDetails=@("auto") Class="my-1 mx-2 " @bind-Value="context.LatestLoginIp"
                    Outlined Label=@context.Description(x => x.LatestLoginIp) />
    </SearchTemplate>

    <ItemColOperTemplate>
        <MButton Color="info" Text StopPropagation OnClick=@(()=>showVerificatList(context.Item.VerificatSignList))>
            @context.Item.Description(it=>it.VerificatSignList)
        </MButton>
        @if (@UserResoures.IsHasButtonWithRole("syssessionexit"))
        {
            <MButton Color="error" Text OnClick="()=>sessionExit(context.Item.Id)">
                @T("强退")
            </MButton>
        }

    </ItemColOperTemplate>

    <HeaderTemplate>
        <MLabel class="text-subtitle">@context.Text</MLabel>
    </HeaderTemplate>

    <ItemColTemplate>
        @switch (context.Header.Value)
        {
            case nameof(context.Item.OnlineStatus):
                <EnableChip EnabledLabel=@T("在线")
                    DisabledLabel=@T("离线")
                    Value="context.Item.OnlineStatus">
                </EnableChip>
                break;
            default:
                @context.Value
                break;
        }

    </ItemColTemplate>
</AppDataTable>

<PModal @bind-Value="IsShowVerificatSignList" OnCancel="() => IsShowVerificatSignList = false"
        Title=@sessionOutput.Description(it => it.VerificatSignList) Height=@("calc(100vh - 300px)")
        MaxWidth="1500">
    @if (IsShowVerificatSignList)
    {
    <AppDataTable @ref="_verificatinfosDatatable" TItem="VerificatInfo"
                  SearchItem="BasePageInput" AddItem="object" EditItem="object"
                  QueryCall="verificatQueryCall"
                  DeleteCall="verificatExit"
                  FilterHeaders="verificatFilterHeaders"
                  IsMenuOperTemplate=false IsShowToolbar IsPage=false
                  ShowDeleteButton=@UserResoures.IsHasButtonWithRole("sysverificatdelete")>

        <ItemColTemplate>
            @switch (context.Header.Value)
            {
                case nameof(context.Item.Device):
                    <MChip Class="ma-1">
                        @(context.Item.Device)
                    </MChip>
                    break;
                case nameof(context.Item.IsOnline):
                    <EnableChip EnabledLabel=@T("在线")
                        DisabledLabel=@T("离线")
                        Value="context.Item.IsOnline">
                    </EnableChip>
                    break;
                case nameof(context.Item.VerificatRemainPercent):
                    <MProgressLinear Color="warning" Value="@(context.Item.VerificatRemainPercent*100)" Height="15" Context="LinearValue">
                        <strong>@($"{LinearValue.ToString("f1")}%")</strong>
                    </MProgressLinear>
                    break;

                default:
                    @context.Value
                    break;
            }

        </ItemColTemplate>

    </AppDataTable>
        
    }

</PModal>

